package com.qkst.website.backstage.controller;


import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.qkst.website.backstage.bean.CatalogBean;
import com.qkst.website.backstage.service.CatalogService;
import com.qkst.website.common.core.BaseController;

/**
 * @author lh
 * @description 产品销售目录控制器
 * @date 2017-05-03
 * @email ahlxlihao@163.com
 *
 */
@Controller
@RequestMapping("/backstage/catalog")
public class CatalogController extends BaseController{

	@Autowired
	private CatalogService catalogService;

	/**
	 * 查询销售目录
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(value = "/list.do", method = { RequestMethod.GET })
	public ModelAndView list(CatalogBean catalog) throws IOException{
		ModelAndView mv=this.backstageModelAndView("catalog/list");
		List<CatalogBean> catalogList = catalogService.list(catalog);
		mv.addObject("catalogList", catalogList);
		return mv;

	}
	
	/**
	 * 添加销售目录
	 * @return
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Map<String, Object> add(CatalogBean catalog){
		Map<String, Object> result = new HashMap<String, Object>();
		catalog=catalogService.save(catalog);
		result.put("catalog", catalog);
		return result;

	}
	
	/**
	 * 删除销售目录
	 * @return
	 */
	@RequestMapping(value = "/delete.do", method = { RequestMethod.POST })
	@ResponseBody
	public Map<String, Object>  delete(CatalogBean catalog){
		Map<String, Object> result = new HashMap<String, Object>();
		boolean flag=catalogService.delete(catalog);
		result.put("isSuccess", flag);
		result.put("catalog", catalog);
		return result;
	}	

}
